package com.polaris.live.common.network

import com.blankj.utilcode.util.StringUtils
import com.polaris.live.translation.R

/**
 * AppException
 *
 * @author Created by 半仙 on 2023/7/31/031 16:45
 */
class AppException : Exception {

    var errorMsg: String //错误消息
    var errCode: Int = 0 //错误码
    var errorLog: String? = null //错误日志
    var throwable: Throwable? = null
    var ext: Map<String, Any>? = null

    constructor(errCode: Int, error: String?, errorLog: String? = "", throwable: Throwable? = null) : super(error) {
        this.errorMsg = error ?: StringUtils.getString(R.string.request_failure)
        this.errCode = errCode
        this.errorLog = errorLog ?: this.errorMsg
        this.throwable = throwable
    }

    constructor(errCode: Int, error: String?, ext: Map<String, Any>? = null) : super(error) {
        this.errorMsg = error ?: StringUtils.getString(R.string.request_failure)
        this.errCode = errCode
        this.ext = ext
    }

    constructor(error: Error, e: Throwable?) : super(error.err) {
        errCode = error.code
        errorMsg = error.err
        errorLog = e?.message
        throwable = e
    }
}